Skip to content

943 Local Setup - Kept Old US Local Setup In place - #1344

Open
technicks89 wants to merge 7 commits into
ChrisTitusTech:mainfrom
technicks89:943_Locale_update
Open

943 Local Setup - Kept Old US Local Setup In place#1344
technicks89 wants to merge 7 commits into
ChrisTitusTech:mainfrom
technicks89:943_Locale_update

Conversation

@technicks89

Copy link
Copy Markdown
Contributor

Type of Change

  • New feature

Description

Added option for new Local Setup (UTF-8 only). Kept original US locale setup in place.

Issues / other PRs related

Screenshots (if applicable)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new “Locale Setup” utility under the Utils tab to help users configure a UTF-8 locale (intended to address Debian’s default 12-hour time/locale experience discussed in #943), while keeping the existing “US Locale Setup” utility available.

Changes:

  • Added a new Utils menu entry for “Locale Setup” pointing to a new locale-setup.sh script.
  • Introduced core/tabs/utils/locale-setup.sh to detect/suggest a locale and generate it.
  • Updated the user guide walkthrough to mention the new utility.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
docs/content/userguide/walkthrough.md Adds “Locale Setup” to the walkthrough list (currently with a small Markdown formatting issue).
core/tabs/utils/tab_data.toml Registers the new “Locale Setup” utility in the Utils catalog (task flaging needs adjustment for privileged edits).
core/tabs/utils/locale-setup.sh New script to suggest and apply a UTF-8 locale (needs hardening for idempotence, clearer failure behavior, and safer network call).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/tabs/utils/tab_data.toml
Comment thread docs/content/userguide/walkthrough.md Outdated
Comment thread core/tabs/utils/locale-setup.sh Outdated
Comment thread core/tabs/utils/locale-setup.sh Outdated
Comment thread core/tabs/utils/locale-setup.sh
…timeout for iso lookup and defaulted to US if fails, addd conditional statements for modifying locale based on Copilot suggestions
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added a Locale Setup utility that suggests a locale and lets you confirm or enter a custom value.
    • Validates custom locale entries and rejects unsupported selections.
    • Applies the selected locale system-wide and generates the required locale when supported.
    • Added Locale Setup to the Utilities tab.
  • Documentation

    • Updated the user walkthrough to explain how to access the new Locale Setup utility.

Walkthrough

Adds an interactive locale setup script that detects locale suggestions, validates input, updates system locale files, runs locale-gen, and registers the utility in metadata and documentation.

Changes

Locale Setup Utility

Layer / File(s) Summary
Locale detection and suggestions
core/tabs/utils/locale-setup.sh
The script sources shared helpers, checks for locale-gen, retrieves a country code, and selects matching locale definitions with a fallback.
Interactive locale configuration
core/tabs/utils/locale-setup.sh
The utility validates custom or numeric locale input, updates /etc/locale.gen and /etc/locale.conf, then runs locale-gen.
Utility catalog and walkthrough
core/tabs/utils/tab_data.toml, docs/content/userguide/walkthrough.md
Adds Locale Setup to the utility catalog and documents it under User Account Manager utilities.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant LocaleSetup as locale-setup.sh
  participant SystemFiles as /etc locale files
  participant LocaleGen as locale-gen
  LocaleSetup->>User: Present locale choices
  User-->>LocaleSetup: Select or enter locale
  LocaleSetup->>SystemFiles: Update locale.gen and locale.conf
  LocaleSetup->>LocaleGen: Generate selected locale
Loading

Suggested reviewers: christitustech

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds locale selection and persistence, but it does not explicitly configure LC_TIME as requested for 24-hour formatting in #943. Add an LC_TIME option or update LC_TIME alongside LANG, including values such as en_GB.UTF-8 or C.UTF-8, and verify Debian and Arch behavior.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title identifies the locale setup change and states that the existing US setup remains available.
Description check ✅ Passed The description identifies the new UTF-8 locale setup, retention of the US setup, and resolution of issue #943.
Out of Scope Changes check ✅ Passed The script, tab registration, and documentation update all support the requested locale setup feature.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
core/tabs/utils/locale-setup.sh (1)

12-46: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use printf instead of echo.

Replace the locale-map and error-message echo calls with printf for portable shell output. As per coding guidelines, “use printf rather than echo for portable formatted output.”

Also applies to: 72-72, 90-90

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/tabs/utils/locale-setup.sh` around lines 12 - 46, Replace every echo
invocation in the locale mapping, fallback, and associated error-message paths
with portable printf calls, including the locations referenced around lines 72
and 90. Preserve each existing locale value, fallback behavior, and
error-message content while ensuring formatting remains equivalent.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/tabs/utils/locale-setup.sh`:
- Around line 12-46: Correct the country-to-locale mappings in the locale
selection case statement: use `gb` for `en_GB.UTF-8` instead of `uk`, map `ch`
to the appropriate Swiss locale instead of falling back, map `sg` to Singapore’s
locale rather than `de_CH.UTF-8`, and update `cf` to the Central African
Republic locale. Preserve all other mappings and the existing default fallback.
- Around line 61-76: Harden the LOCALE validation loop in locale setup to accept
C.UTF-8, require a safe locale-character whitelist that excludes
command-injection metacharacters, and verify the locale is available before any
/etc/environment update. Preserve the existing format validation for valid UTF-8
locales, then only pass validated values to the escalated sed commands.

In `@core/tabs/utils/tab_data.toml`:
- Around line 151-155: Add a command_exists precondition to the Locale Setup
entry in the tab data, checking for locale-gen before displaying or running
locale-setup.sh; follow the existing utility entries’ condition syntax and leave
the task metadata unchanged.

---

Nitpick comments:
In `@core/tabs/utils/locale-setup.sh`:
- Around line 12-46: Replace every echo invocation in the locale mapping,
fallback, and associated error-message paths with portable printf calls,
including the locations referenced around lines 72 and 90. Preserve each
existing locale value, fallback behavior, and error-message content while
ensuring formatting remains equivalent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d497e908-958e-40f5-af9e-b88ccd0f11ec

📥 Commits

Reviewing files that changed from the base of the PR and between 41fc991 and c3c28d3.

📒 Files selected for processing (3)
  • core/tabs/utils/locale-setup.sh
  • core/tabs/utils/tab_data.toml
  • docs/content/userguide/walkthrough.md

Comment thread core/tabs/utils/locale-setup.sh Outdated
Comment thread core/tabs/utils/locale-setup.sh Outdated
Comment thread core/tabs/utils/tab_data.toml Outdated
@ChrisTitusTech

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a729863eaa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread core/tabs/utils/locale-setup.sh Outdated
Comment thread core/tabs/utils/tab_data.toml Outdated
Comment thread core/tabs/utils/locale-setup.sh Outdated
Comment on lines +61 to +64
case "$LOCALE" in
*[![:alnum:]_.@-]*|'') ;;
*.UTF-8) break ;;
esac

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate the locale before persisting it

For any syntactically plausible but unsupported input such as en_UK.UTF-8, this check accepts the value, after which the script writes it to /etc/environment, /etc/locale.gen, and /etc/locale.conf before locale-gen reports failure. The failed run therefore leaves the system configured with an invalid locale; verify the value against the installed locale definitions before modifying any files.

Useful? React with 👍 / 👎.

Comment thread core/tabs/utils/locale-setup.sh
Comment thread core/tabs/utils/locale-setup.sh Outdated
Comment thread core/tabs/utils/locale-setup.sh Outdated
Comment thread core/tabs/utils/tab_data.toml

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/tabs/utils/locale-setup.sh`:
- Around line 9-10: Update the locale selection and validation logic around
suggested_locales to derive choices from /usr/share/i18n/SUPPORTED (or an
equivalent supported-locale list), accepting only validated full UTF-8
identifiers and special-casing C.UTF-8. Keep each source filename separate from
its generated locale identifier, reject traversal or arbitrary files in custom
input, and ensure numeric selections and LANG values retain the .UTF-8 suffix.
- Around line 42-50: Update the numeric validation in the choice-handling case
statement to reject zero before the sed lookup, while continuing to accept
positive integer selections. Preserve the existing “Invalid selection.” response
and avoid invoking sed for a zero choice.
- Around line 6-7: Validate iso against the exact two-letter pattern
^[A-Za-z]{2}$ before filtering, and update the suggested_locales logic to search
localeNames for an exact territory match such as _CA rather than using an
unanchored grep. Ensure invalid or empty responses produce no suggested locales.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c0bddf18-0085-47cd-9a1c-9219543356e6

📥 Commits

Reviewing files that changed from the base of the PR and between c48f44a and 3ab80bd.

📒 Files selected for processing (2)
  • core/tabs/utils/locale-setup.sh
  • core/tabs/utils/tab_data.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • core/tabs/utils/tab_data.toml

Comment on lines +6 to +7
iso=$(curl -4fsSL --max-time 5 https://ifconfig.io/country_code 2>/dev/null) || iso="US"
suggested_locales=$(ls /usr/share/i18n/locales/ | grep -i "$iso" || true)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/sh
set -e

printf 'Repository files matching locale-setup.sh:\n'
fd -a 'locale-setup\.sh$' . || true

file="$(fd 'locale-setup\.sh$' . | head -n 1 || true)"
if [ -n "$file" ]; then
  printf '\nFile: %s\n' "$file"
  wc -l "$file"
  cat -n "$file"
fi

printf '\nRelevant grep/iso usages in core/tabs/utils/locale-setup.sh:\n'
if [ -n "$file" ]; then
  rg -n -C 3 'iso=|ifconfig|country_code|suggested_locales|grep|locales/' "$file" || true
fi

printf '\nSample grep behavior with CA on common locale filename set:\n'
python3 - <<'PY'
from pathlib import Path
samples = sorted({
    "ca_ES.utf8",
    "ca_ES@euro",
    "CA",
    "usa",
    "en_US.utf8",
    "de_DE.utf8",
    "us",
    "CA",
})(
    name for name in [
        "ca_ES.utf8", "ca_ES@euro", "CA", "usa", "en_US.utf8", "de_DE.utf8", "us", "CA",
    ]
)
for pattern in ["", "CA", "CA\\b"]:
    print("pattern", repr(pattern), ":")
    for name in samples:
        matched = True
        try:
            import subprocess
            res = subprocess.run(["grep", "-i", pattern, name], input=name+"\n", text=True, capture_output=True)
            matched = res.returncode == 0
        except Exception as e:
            matched = False
        print(name, matched)
PY

Repository: ChrisTitusTech/linutil

Length of output: 5204


🏁 Script executed:

#!/bin/sh
set -e

printf 'Repository files matching locale-setup.sh:\n'
fd 'locale-setup\.sh$' . || true

file="$(fd 'locale-setup\.sh$' . | head -n 1 || true)"
if [ -n "$file" ]; then
  printf '\nFile: %s\n' "$file"
  wc -l "$file"
  cat -n "$file"
fi

printf '\nSample grep behavior with CA on common locale filename set:\n'
python3 - <<'PY'
import subprocess

samples = sorted([
    "ca_ES.utf8",
    "ca_ES@euro",
    "CA",
    "usa",
    "en_US.utf8",
    "de_DE.utf8",
    "us",
    "CA",
])
for pattern in ["", "CA", "CA\\b"]:
    print("pattern", repr(pattern), ":")
    for name in samples:
        result = subprocess.run(["grep", "-i", pattern, name], input=name + "\n", text=True, capture_output=True)
        print(name, result.returncode == 0)
PY

Repository: ChrisTitusTech/linutil

Length of output: 3681


Validate the country code before filtering locales.

iso comes from an HTTP response and is used unanchored in grep. Use ^[A-Za-z]{2}$ and search localeNames for an exact territory match such as _CA, so false positives like ca_* and empty iso values do not enter suggested_locales.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/tabs/utils/locale-setup.sh` around lines 6 - 7, Validate iso against the
exact two-letter pattern ^[A-Za-z]{2}$ before filtering, and update the
suggested_locales logic to search localeNames for an exact territory match such
as _CA rather than using an unanchored grep. Ensure invalid or empty responses
produce no suggested locales.

Comment on lines +9 to +10
if [ -z "$suggested_locales" ]; then
suggested_locales=$(ls /usr/share/i18n/locales/)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Use validated full UTF-8 locale identifiers.

The fallback lists every file in /usr/share/i18n/locales, and the custom branch accepts any regular file below that directory. A path such as ../../../etc/passwd can therefore pass the file check when the target exists, but it is not a locale. The code also rejects standard inputs such as en_GB.UTF-8 and C.UTF-8 unless matching source files exist. Numeric choices produce bare names such as en_GB, which later become LANG=en_GB.

Build choices and custom validation from /usr/share/i18n/SUPPORTED or an equivalent supported-locale list. Special-case C.UTF-8. Keep the source filename separate from the generated locale identifier. Debian documents /usr/share/i18n/SUPPORTED as the supported-locale list and uses full .UTF-8 values for locale configuration. (manpages.debian.org)

Suggested input model
-        suggested_locales=$(ls /usr/share/i18n/locales/ | grep -i "$iso" || true)
+        supported_locales=$(awk '$2 == "UTF-8" { print $1 }' /usr/share/i18n/SUPPORTED)
+        suggested_locales=$(printf '%s\n' "$supported_locales" |
+            grep -iE "(^|_)${iso}([.@]|$)" || true)

         if [ -z "$suggested_locales" ]; then
-            suggested_locales=$(ls /usr/share/i18n/locales/)
+            suggested_locales=$supported_locales
         fi
...
-                if [ -f "/usr/share/i18n/locales/$custom_locale" ]; then
+                if [ "$custom_locale" = "C.UTF-8" ] ||
+                   printf '%s\n' "$supported_locales" |
+                   grep -qxF "$custom_locale"; then

Also applies to: 24-40, 48-52

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/tabs/utils/locale-setup.sh` around lines 9 - 10, Update the locale
selection and validation logic around suggested_locales to derive choices from
/usr/share/i18n/SUPPORTED (or an equivalent supported-locale list), accepting
only validated full UTF-8 identifiers and special-casing C.UTF-8. Keep each
source filename separate from its generated locale identifier, reject traversal
or arbitrary files in custom input, and ensure numeric selections and LANG
values retain the .UTF-8 suffix.

Comment on lines +42 to +50
case "$choice" in
''|*[!0-9]*)
printf "%s\n" "Invalid selection."
exit 1
;;
esac
LOCALE=$(printf "%s\n" "$suggested_locales" | sed -n "${choice}p")
if [ -z "$LOCALE" ]; then
printf "%s\n" "Invalid selection."

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/sh
set -eu

echo "== locate file =="
fd -a 'locale-setup.sh' . || true

echo "== relevant file excerpt =="
if [ -f core/tabs/utils/locale-setup.sh ]; then
  nl -ba core/tabs/utils/locale-setup.sh | sed -n '1,90p'
fi

echo "== sed on input 0p =="
printf 'line\n' | sed -n '0p' || true
printf 'line\n' | sed -n '1p' || true

echo "== sed availability =="
sed --version | head -n 1 || true

Repository: ChrisTitusTech/linutil

Length of output: 424


🏁 Script executed:

#!/bin/sh
set -eu

echo "== relevant file excerpt =="
if [ -f core/tabs/utils/locale-setup.sh ]; then
  awk '{printf "%3d\t%s\n", NR, $0}' core/tabs/utils/locale-setup.sh | sed -n '1,120p'
fi

echo "== shell behavior for sed 0p under set -e =="
tmp="$(mktemp)"
trap 'rm -f "$tmp"' EXIT
printf 'line\n' > "$tmp"
(
  set -e
  sed -n '0p' "$tmp"
  status=$?
  printf 'sed status: %s\n' "$status"
)
status=${status:-0}
printf 'outer status: %s\n' "$status"

Repository: ChrisTitusTech/linutil

Length of output: 3027


Reject 0 before the sed lookup.

The menu uses 1-based numbering, but the current validation allows 0. sed -n '0p' fails before reaching the empty-result check, and because this script runs with set -e, the selection cannot print “Invalid selection.” Reject zero as an invalid choice.

Minimal fix for zero
-                ''|*[!0-9]*)
+                ''|0|*[!0-9]*)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
case "$choice" in
''|*[!0-9]*)
printf "%s\n" "Invalid selection."
exit 1
;;
esac
LOCALE=$(printf "%s\n" "$suggested_locales" | sed -n "${choice}p")
if [ -z "$LOCALE" ]; then
printf "%s\n" "Invalid selection."
case "$choice" in
''|0|*[!0-9]*)
printf "%s\n" "Invalid selection."
exit 1
;;
esac
LOCALE=$(printf "%s\n" "$suggested_locales" | sed -n "${choice}p")
if [ -z "$LOCALE" ]; then
printf "%s\n" "Invalid selection."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/tabs/utils/locale-setup.sh` around lines 42 - 50, Update the numeric
validation in the choice-handling case statement to reject zero before the sed
lookup, while continuing to accept positive integer selections. Preserve the
existing “Invalid selection.” response and avoid invoking sed for a zero choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding a option to change to 24 hour format in Debian

3 participants